package org.dreamwork.persistence;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2009-8-21
 * Time: 11:32:40
 */
public class Parameter implements Serializable {
    public final String fieldName;
    public final String name;
    public final Object value;
    public final Operator operator;

    public Parameter (String name, Object value, Operator operator) {
        this.name = name;
        this.value = value;
        this.operator = operator;
        this.fieldName = name;
    }

    public Parameter (String fieldName, String name, Object value, Operator operator) {
        this.fieldName = fieldName;
        this.name = name;
        this.value = value;
        this.operator = operator;
    }

    @Override
    public String toString () {
        switch (operator) {
            case BETWEEN :
                return fieldName + " between :" + name + "1 AND :" + name + "2";
            case EQ:
                return fieldName + " = :" + name;
            case NE:
                return fieldName + " <> :" + name;
            case LT:
                return fieldName + " < :" + name;
            case LE :
                return fieldName + " <= :" + name;
            case GT :
                return fieldName + " > :" + name;
            case GE :
                return fieldName + " >= :" + name;
            case IN :
                return fieldName + " in (:" + name + ")";
            case NOT_IN :
                return fieldName + " not in (:" + name + ")";
            case IS_NULL :
                return fieldName + " is null";
            case IS_NOT_NULL :
                return fieldName + " is not null";
            case LIKE :
            case LEFT_LIKE :
            case RIGHT_LIKE :
                return fieldName + " like :" + name;
            default :
                return "";
        }
    }
}